<?php
$data = array('mch_id' => '1241303802', 'nonce_str' => md5(time()));
$postData = $data + ['sign'=>strtoupper(md5(http_build_query($data) . "&key=1234"))];
$xml = '<xml>';
foreach ($postData as $k => $v) {
    $xml .= '<' . $k .'><![CDATA[' . $v . ']]></' . $k .'>';
}
$xml .= '</xml>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://apitest.mch.weixin.qq.com/sandboxnew/pay/getsignkey');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER,0);

$content  = curl_exec($ch);
curl_close($ch);

$toXml = simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA);
$arrXml = (array)$toXml;

if ($arrXml['return_code'] == 'SUCCESS') {
    die('sucess');
}
if ($arrXml['return_code'] == 'FAIL') {
    die("no success:" . $arrXml['return_msg'] . "；" . "<a hre='https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=23_4'>点我查看如何安装微信要求的根CA证书</a>");
}

?>